package wechat.rcv.controller;

import com.google.common.base.Objects;
import com.shrcl.engineerprocess.domain.CertificationNotification;
import com.shrcl.engineerprocess.domain.Engineer;
import com.shrcl.engineerprocess.domain.EngineerCostEstimation;
import com.shrcl.engineerprocess.domain.EngineerProjectInitNotification;
import com.shrcl.engineerprocess.domain.EngineerTraining;
import com.shrcl.engineerprocess.domain.Notification;
import com.shrcl.engineerprocess.domain.TrainingNotification;
import com.shrct.businessprocess.organization.RCEnterprise;
import com.shrct.businessprocess.project.RCProject;
import edu.fudan.mylang.pf.IObjectFactory;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.log4j.Logger;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.InputOutput;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import wechat.rcv.controller.WXNotification;

@Controller
@SuppressWarnings("all")
public class NotificationDispatcher {
  private final static Logger logger = Logger.getLogger(NotificationDispatcher.class.getName());
  
  @Autowired
  private IObjectFactory entities;
  
  @RequestMapping(value = "/notificationdetail")
  public String process(@RequestParam(value = "notificationId", defaultValue = "") final Long notificationId, final Model model) {
    String _xblockexpression = null;
    {
      NotificationDispatcher.logger.info("=========>NotificationDispatcher.processs<============");
      NotificationDispatcher.logger.info(("=========>NotificationDispatcher.notificationId<============" + notificationId));
      String hpage = "error";
      try {
        final Notification n = this.entities.<Notification>get(Notification.class, notificationId);
        String _notificationType = n.getNotificationType();
        String _plus = ("=========>NotificationDispatcher.type<============" + _notificationType);
        NotificationDispatcher.logger.info(_plus);
        boolean _equals = Objects.equal(n, null);
        if (_equals) {
          model.addAttribute("errormsg", "Invalid id");
        } else {
          if ((n instanceof EngineerProjectInitNotification)) {
            InputOutput.<String>println("=======>NotificationDispatcher.EngineerProjectInitNotification<========");
            model.addAttribute("notificationId", notificationId);
            WXNotification _wXNotification = new WXNotification();
            Date _notifyDate = ((EngineerProjectInitNotification)n).getNotifyDate();
            int _day = _notifyDate.getDay();
            String _weekDay = _wXNotification.getWeekDay(Integer.valueOf(_day));
            model.addAttribute("noti_weekday", _weekDay);
            SimpleDateFormat _simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date _notifyDate_1 = ((EngineerProjectInitNotification)n).getNotifyDate();
            String _format = _simpleDateFormat.format(_notifyDate_1);
            model.addAttribute("noti_date", _format);
            EngineerCostEstimation _engineerCostEstimation = ((EngineerProjectInitNotification)n).getEngineerCostEstimation();
            RCProject _project = _engineerCostEstimation.getProject();
            String _name = _project.getName();
            model.addAttribute("name", _name);
            EngineerCostEstimation _engineerCostEstimation_1 = ((EngineerProjectInitNotification)n).getEngineerCostEstimation();
            RCProject _project_1 = _engineerCostEstimation_1.getProject();
            RCEnterprise _customer = _project_1.getCustomer();
            String _name_1 = _customer.getName();
            model.addAttribute("customer", _name_1);
            EngineerCostEstimation _engineerCostEstimation_2 = ((EngineerProjectInitNotification)n).getEngineerCostEstimation();
            Engineer _postSaleManager = _engineerCostEstimation_2.getPostSaleManager();
            String _name_2 = _postSaleManager.getName();
            model.addAttribute("salemanager", _name_2);
            hpage = "tscnotification";
          } else {
            if ((n instanceof TrainingNotification)) {
              InputOutput.<String>println("=======>NotificationDispatcher.TrainingNotification<========");
              model.addAttribute("notificationId", notificationId);
              WXNotification _wXNotification_1 = new WXNotification();
              Date _notifyDate_2 = ((TrainingNotification)n).getNotifyDate();
              int _day_1 = _notifyDate_2.getDay();
              String _weekDay_1 = _wXNotification_1.getWeekDay(Integer.valueOf(_day_1));
              model.addAttribute("noti_weekday", _weekDay_1);
              SimpleDateFormat _simpleDateFormat_1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
              Date _notifyDate_3 = ((TrainingNotification)n).getNotifyDate();
              String _format_1 = _simpleDateFormat_1.format(_notifyDate_3);
              model.addAttribute("noti_date", _format_1);
              EngineerTraining _engineerTraining = ((TrainingNotification)n).getEngineerTraining();
              String _name_3 = _engineerTraining.getName();
              model.addAttribute("name", _name_3);
              EngineerTraining _engineerTraining_1 = ((TrainingNotification)n).getEngineerTraining();
              String _topic = _engineerTraining_1.getTopic();
              model.addAttribute("topic", _topic);
              EngineerTraining _engineerTraining_2 = ((TrainingNotification)n).getEngineerTraining();
              String _trainer = _engineerTraining_2.getTrainer();
              model.addAttribute("trainer", _trainer);
              EngineerTraining _engineerTraining_3 = ((TrainingNotification)n).getEngineerTraining();
              String _location = _engineerTraining_3.getLocation();
              model.addAttribute("location", _location);
              SimpleDateFormat _simpleDateFormat_2 = new SimpleDateFormat("yyyy-MM-dd");
              EngineerTraining _engineerTraining_4 = ((TrainingNotification)n).getEngineerTraining();
              Date _startdate = _engineerTraining_4.getStartdate();
              String _format_2 = _simpleDateFormat_2.format(_startdate);
              model.addAttribute("startDate", _format_2);
              SimpleDateFormat _simpleDateFormat_3 = new SimpleDateFormat("yyyy-MM-dd");
              EngineerTraining _engineerTraining_5 = ((TrainingNotification)n).getEngineerTraining();
              Date _enddate = _engineerTraining_5.getEnddate();
              String _format_3 = _simpleDateFormat_3.format(_enddate);
              model.addAttribute("endDate", _format_3);
              hpage = "trainingnotification";
            } else {
              if ((n instanceof CertificationNotification)) {
                InputOutput.<String>println("=======>NotificationDispatcher.<========CertificationNotification");
              }
            }
          }
        }
      } catch (final Throwable _t) {
        if (_t instanceof Exception) {
          final Exception e = (Exception)_t;
          e.printStackTrace();
        } else {
          throw Exceptions.sneakyThrow(_t);
        }
      }
      _xblockexpression = hpage;
    }
    return _xblockexpression;
  }
}
